package com.mt.controller;


import com.mt.constants.Result;
import com.mt.enums.FilmListType;
import com.mt.pojo.FilmComment;
import com.mt.service.FilmCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Wang
 * @since 2020-11-12
 */
@RestController
@RequestMapping("/comment")
@Slf4j
public class FilmCommentController {
    @Autowired
    FilmCommentService commentService;

    @PostMapping("/add")
    public Result addFilmComment(@RequestBody FilmComment comment,@RequestParam("userId") String userId) {
        comment.setUserId(userId);
        log.debug(comment.toString());
        Result<Object> result = new Result<>();
        if (commentService.addFilmComment(comment)){
            result.success();
        }
        return result;
    }
    @GetMapping("/check")
    public Result checkUserIsComment(@RequestParam("userId")String userId, int filmId){
        Result<Object> result = new Result<>();
        result.success(commentService.checkUserIsComment(userId, filmId));
        return result;
    }

    @GetMapping("/myComment")
    public Result getUserComments(@RequestParam("userId")String userId,int filmId){
        Result<Object> result = new Result<>();
        FilmComment comments = commentService.getUserComments(userId, filmId);
        result.success(comments);
        return result;
    }

    @GetMapping("/{filmId}")
    //int currentPage, int pageSize,
    public Result pageCommentByFilmId(@RequestParam("userId")String userId,@PathVariable("filmId") int filmId, FilmListType listType){
//        log.debug("传入参数 :currentPage:{} ,pageSize:{} ,userId:{} ,filmId:{} ,listType:{}",
//                currentPage,pageSize,userId,filmId,listType.getMsg());
        Result<Object> result = new Result<>();
        List<FilmComment> commentList = commentService.pageCommentByFilmId(1, 10,userId, filmId, listType);
        result.success(commentList);
        return result;
    }

    public Result deleteComment(int CommentId){
        log.debug("传入参数 CommentId:{}",CommentId);
        Result<Object> result = new Result<>();
        if (commentService.deleteComment(CommentId)){
            result.success();
        }
        return result;
    }



}
